//
//  GSTabBarController.swift
//  SinaWeiboDay1
//
//  Created by SamuelChan on 16/4/8.
//  Copyright © 2016年 SamuelChan. All rights reserved.
//

import UIKit

class GSTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let gsTabBar = GSTabBar()
        setValue(gsTabBar, forKey:"tabBar")
        gsTabBar.callBack = {
            () ->() in
            print("我点击了加号按钮")
        }
        
        /**设置tabBarController的子控制器*/
        setTabChildControllers()
    }
    //测试UITabBarController的控制是否一开始就加载出来的
//    override func viewDidAppear(animated: Bool) {
//        super.viewDidAppear(animated)
//        for child in childViewControllers{
////        print((child as! UINavigationController).viewControllers)
//        }
//    }
    private func setTabChildControllers(){
        
        setTabChildVc(GSHomeViewControllerTableViewController(), pic: "tabbar_home", name: "首页")
        setTabChildVc(GSMessageViewController(), pic: "tabbar_message_center", name: "消息")
        setTabChildVc(GSDiscoverTableViewController(), pic: "tabbar_discover", name: "发现")
        setTabChildVc(GSProfileViewController(), pic: "tabbar_profile", name: "我")
        
        
    }
    
    private func setTabChildVc (vc:UIViewController,pic:String,name:String){
        
        vc.title = name
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        vc.tabBarItem.image = UIImage(named:pic)
        vc.tabBarItem.selectedImage = UIImage(named:pic + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}
